# """
# This is ArrayReader's API interface.
# You should not implement it, or speculate about its implementation
# """
class ArrayReader(object):
    # Compares the sum of arr[l..r] with the sum of arr[x..y]
    # return 1 if sum(arr[l..r]) > sum(arr[x..y])
    # return 0 if sum(arr[l..r]) == sum(arr[x..y])
    # return -1 if sum(arr[l..r]) < sum(arr[x..y])
    def compareSub(self, l: int, r: int, x: int, y: int) -> int:
        pass

        # Returns the length of the array

    def length(self) -> int:
        pass


class Solution:
    def getIndex(self, reader: 'ArrayReader') -> int:
        size = reader.length()
        left, right = 0, size - 1
        while left < right:
            # 当前有偶数个
            if (right - left + 1) % 2 == 0:
                mid = (left + right) // 2
                res = reader.compareSub(left, mid, mid + 1, right)
                if res == 1:
                    right = mid
                elif res == -1:
                    left = mid + 1
            # 当前有奇数个
            else:
                mid = (left + right) // 2
                res = reader.compareSub(left, mid - 1, mid + 1, right)
                if res == 1:
                    right = mid - 1
                elif res == -1:
                    left = mid + 1
                else:
                    return mid

        return left


if __name__ == "__main__":
    pass
